local status, formatter = pcall(require, 'formatter')
if not status then
  vim.notify('没有找到 formatter')
  return
end

formatter.setup({
  filetype = {
    lua = {
      require('formatter.filetypes.lua').stylua,
    },
    go = {
      require('formatter.filetypes.go').gofmt,
      require('formatter.filetypes.go').goimports,
      function()
        return {
          exe = 'goimports-reviser',
          args = {
            '-rm-unused',
            '-set-alias',
            '-format',
            '-output=stdout',
            vim.fn.fnameescape(vim.api.nvim_buf_get_name(0)),
          },
          stdin = true,
        }
      end,
    },
    json = {
      function()
        return {
          exe = 'npx prettier',
          args = {
            '--stdin-filepath',
            vim.fn.fnameescape(vim.api.nvim_buf_get_name(0)),
            '--single-quote',
          },
          stdin = true,
        }
      end,
      -- require('formatter.filetypes.json').jq,
      -- require('formatter.filetypes.json').fixjson,
    },
    yaml = {
      require('formatter.filetypes.yaml').pyaml,
    },
    toml = {
      require('formatter.filetypes.toml').taplo,
    },
  },
})

-- format on save
vim.api.nvim_exec(
  [[
    augroup FormatAutogroup
    autocmd!
    autocmd BufWritePost *.lua FormatWrite
    autocmd BufWritePost *.go FormatWrite
    augroup END
]],
  true
)

vim.api.nvim_exec(
  [[
augroup CocPairs
augroup END
]],
  true
)
